package cn.wolfcode.car.service.impl;

import cn.wolfcode.car.domain.ConsumptionItem;
import cn.wolfcode.car.mapper.ConsumptionItemMapper;
import cn.wolfcode.car.qo.ConsumptionItemQueryObject;
import cn.wolfcode.car.service.IConsumptionItemService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class ConsumptionItemServiceImpl implements IConsumptionItemService {

    @Autowired
    private ConsumptionItemMapper consumptionItemMapper;

    @Override
    public int delete(Long id) {
        return consumptionItemMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int save(ConsumptionItem record) {
        return consumptionItemMapper.insert(record);
    }

    @Override
    public ConsumptionItem get(Long id) {
        return consumptionItemMapper.selectByPrimaryKey(id);
    }

    @Override
    public PageInfo<ConsumptionItem> list(ConsumptionItemQueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<ConsumptionItem> list = consumptionItemMapper.selectForPage(qo);
        return new PageInfo<>(list);
    }

    @Override
    public List<ConsumptionItem> listAll() {
        return consumptionItemMapper.selectAll();
    }

    @Override
    public int update(ConsumptionItem record) {
        return consumptionItemMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<ConsumptionItem> selectBycno(String cno) {
        return consumptionItemMapper.selectBycno(cno);
    }

    @Override
    public void deleteByCno(String cno) {
        consumptionItemMapper.deleteByCno(cno);
    }


}
